class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int res = 0, count = 0;
        for(int i = 0; i < nums.size(); i++) // 遍历
        {
            if(count == 0)//count=0就更换候选人，投他一票
            {
                res = nums[i]; 
                count++;
            }
            else // 开始记票
            {
                res == nums[i] ? count++ : count--;
            }
        }
        return res;
    }
};